<?php 
/***
    Amrita ITEWS - Copyright (C) 2009 Amrita Vishwa Vidyapeetham, Amritapuri.
                                     (http://www.amrita.edu)
    ***************************************************************************
    This file is part of the Amrita ITEWS distribution.
    Amrita ITEWS is free software; you can redistribute it and/or modify it 
    under the terms of the GNU General Public License (version 2) as published 
    by the Free Software Foundation AND MODIFIED BY the Amrita ITEWS exception.
    ***NOTE*** The exception to the GPL is included to allow you to distribute
    a combined work that includes Amrita ITEWS without being obliged to provide
    the source code for proprietary components outside of the Amrita ITEWS
    software. Amrita ITEWS is distributed in the hope that it will be useful, 
    but WITHOUT ANY WARRANTY; without even the implied warranty of 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
    Public License for more details. You should have received a copy of the GNU
    General Public License and the Amrita ITEWS license exception along with 
    Amrita ITEWS if not then it can be viewed here: 
    http://itews.amrita.ac.in/license.html.
    
    Documentation, latest information, license and contact details are at:
    http://itews.amrita.ac.in/
 
    Amrita ITEWS source code can be found at:
    http://code.google.com/p/itews"; 
    
    The initial code-base of Amrita ITEWS was developed by Amrita Vishwa 
    Vidyapeetham as part of the project titled,\"Intelligent & Interactive 
    Telematics using Emerging Wireless Technologies for Transport Systems 
    (ITEWS)\" sponsored by Technology Information Forecasting and Assessment 
    Council (TIFAC), India.
***/
?><?php
//set_error_handler('errorHandler',E_WARNING|E_ERROR|E_NOTICE);
//http://www.tonymarston.net/php-mysql/errorhandler.html
function errorHandler ($errno, $errstr, $errfile, $errline, $errcontext)
{
   switch ($errno)
   {
      case E_USER_WARNING:
      case E_USER_NOTICE:
			break;//we are taking care of the ones above
      case E_WARNING:
      case E_NOTICE:
      case E_CORE_WARNING:
      case E_COMPILE_WARNING:
      case E_USER_ERROR:
      case E_ERROR:
      case E_PARSE:
      case E_CORE_ERROR:
      case E_COMPILE_ERROR:
	/***********
	  global $query;

         if (eregi('^(sql)$', $errstr)) {
            $MYSQL_ERRNO = mysql_errno();
            $MYSQL_ERROR = mysql_error();
            $errstr = "MySQL error: $MYSQL_ERRNO : $MYSQL_ERROR";
         } else {
            $query = NULL;
         } // if
		 $errorstring = "<h2>" .date('Y-m-d H:i:s') ."</h2>\n";

         $errorstring .= "<p>Fatal Error: $errstr (# $errno).</p>\n";

         if ($query) $errorstring .= "<p>SQL query: $query</p>\n";

         $errorstring .= "<p>Error in line $errline of file '$errfile'.</p>\n";
         $errorstring .= "<p>Script: '{$_SERVER['PHP_SELF']}'.</p>\n";
         if (isset($errcontext['this'])) {
            if (is_object($errcontext['this'])) {
               $classname = get_class($errcontext['this']);
               $parentclass = get_parent_class($errcontext['this']);
               $errorstring .= "<p>Object/Class: '$classname', Parent Class: '$parentclass'.</p>\n";
            } // if
         } // if

         //echo "<h2>This system is temporarily unavailable</h2>\n";
         //echo "<p>The following has been reported to the administrator:</p>\n";
         //echo "<b><font color='red'>\n$errorstring\n</b></font>";
		*******/
		print_r(error_get_last());
		$error = error_get_last();
		$errorstring = $error['message'];
		log_error($errorstring,E_USER_WARNING,__FILE__,__LINE__);//change all to warning
		
		$_SESSION['flashMessage'] = 'This system is temporarily unavailable';
		$_SESSION['flashType'] = 'error';
		$_SESSION['flashNumber'] = '999';

		 
		//error_log($errorstring, 1, $_SERVER['SERVER_ADMIN']);
		
        //$logfile = $_SERVER['DOCUMENT_ROOT'] .'/errorlog.html';
        //error_log($errorstring, 3, $logfile);
		/************
         session_start();
         session_unset();
         session_destroy();
		 *********/
         //die();
      default:
         break;
   } // switch
} // errorHandler
?>